package com.string;

/**
 * @author: csh
 * @Date: 2021/6/22 11:27
 * @Description:
 */
public class StringTest3 {
    public static void main(String[] args) {
        String s1 = "javaEE";
        String s2 = "hadoop";
        String s3 = "javaEEhadoop";
        String s4 = "javaEE" + "hadoop";
        String s5 = s1+ "hadoop";
        String s6 ="javaEE"+s2;
        String s7 = s1 + s2;

        System.out.println(s3 == s4);   //true
        System.out.println(s3 == s5);   //false s1是变量 不能编译优化
        System.out.println(s3 == s6);   //false s2是变量 不能编译优化
        System.out.println(s3 == s7);   //false s1 s2都是变量
        System.out.println(s5 == s6);   //false s1 s2都是变量
        System.out.println(s5 == s7);   //false 存在变量
        System.out.println(s6 == s7);   //false 存在变量

        String s8 = s6.intern();
        System.out.println(s3 == s8); //true intern()会在常量池中先存放
    }
}
